Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

SourceCitation.setLang   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 4
loc 4
rs 10
1 View Code Duplication
var ExtensibleData = require('./ExtensibleData'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    utils = require('./utils');
3
4
/**
5
 * A source citation.
6
 * 
7
 * @constructor
8
 * @apram {Object} [json]
9
 */
10
var SourceCitation = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof SourceCitation)){
14
    return new SourceCitation(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(SourceCitation.isInstance(json)){
19
    return json;
20
  }
21
  
22
  ExtensibleData.call(this, json);
23
  
24
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
25
    this.setLang(json.lang);
26
    this.setValue(json.value);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
27
  }
28
};
29
30
SourceCitation.prototype = Object.create(ExtensibleData.prototype);
31
32
SourceCitation._gedxClass = SourceCitation.prototype._gedxClass = 'GedcomX.SourceCitation';
33
34
/**
35
 * Check whether the given object is an instance of this class.
36
 * 
37
 * @param {Object} obj
38
 * @returns {Boolean}
39
 */
40
SourceCitation.isInstance = function(obj){
41
  return utils.isInstance(obj, this._gedxClass);
42
};
43
44
/**
45
 * Get the lang
46
 * 
47
 * @returns {String} lang
48
 */
49
SourceCitation.prototype.getLang = function(){
50
  return this.lang;
51
};
52
53
/**
54
 * Set the lang
55
 * 
56
 * @param {String} lang
57
 * @returns {SourceCitation} This instance
58
 */
59
SourceCitation.prototype.setLang = function(lang){
60
  this.lang = lang;
61
  return this;
62
};
63
64
/**
65
 * Get the value
66
 * 
67
 * @returns {String} value
68
 */
69
SourceCitation.prototype.getValue = function(){
70
  return this.value;
71
};
72
73
/**
74
 * Set the value
75
 * 
76
 * @param {String} value
77
 * @returns {SourceCitation} This instance
78
 */
79
SourceCitation.prototype.setValue = function(value){
80
  this.value = value;
81
  return this;
82
};
83
84
/**
85
 * Export the object as JSON
86
 * 
87
 * @return {Object} JSON object
88
 */
89
SourceCitation.prototype.toJSON = function(){
90
  var json = ExtensibleData.prototype.toJSON.call(this);
91
  
92
  if(this.lang){
93
    json.lang = this.lang;
94
  }
95
  
96
  if(this.value){
97
    json.value = this.value;
98
  }
99
  
100
  return json;
101
};
102
103
module.exports = SourceCitation;